package mars.activity;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.Toast;
import android.widget.TabHost.OnTabChangeListener;

public class Msg extends TabActivity{
	private TabHost tabhost;
	private Button return2;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.msg);    
		tabhost = (TabHost)findViewById(android.R.id.tabhost);
		return2 = (Button)findViewById(R.id.return2); 
	    tabhost = getTabHost();
        tabhost.setup();
        Intent intentrec=getIntent();
        intentrec.setClass(this,receiveActivity.class);
        tabhost.addTab(tabhost.newTabSpec("tab_5")
		         .setContent(intentrec).setIndicator(null,getResources().getDrawable(R.drawable.gmail)));
        Intent intentsen=getIntent();
        intentsen.setClass(this,sendActivity.class);
		        tabhost.addTab(tabhost.newTabSpec("tab_6")
		         .setContent(intentsen).setIndicator(null,getResources().getDrawable(R.drawable.talk)));
		        tabhost.setCurrentTab(0);
		        return2.setOnClickListener(new Button.OnClickListener()
		        {
					public void onClick(View v) {
						// TODO Auto-generated method stub					
							Intent intent=new Intent();
							intent.setClass(Msg.this, User.class);
							Msg.this.startActivity(intent);
							finish();
					}	
		        });
		        tabhost.setOnTabChangedListener(new OnTabChangeListener()
		        {
		            // TODO Auto-generated method stub
		            public void onTabChanged(String tabId)
		            {
		            	if(tabId=="tab_5"){
		           Toast.makeText(Msg.this,R.string.tab5,Toast.LENGTH_SHORT).show();
		            }
		            	if(tabId=="tab_6"){
		    		   Toast.makeText(Msg.this,R.string.tab6,Toast.LENGTH_SHORT).show();
		                }
		            }
		        });
	}	
	 @Override
		public boolean onCreateOptionsMenu(Menu menu) {
			// TODO Auto-generated method stub
			menu.add(0,1,1,R.string.exit);
			menu.add(0,2,2,R.string.options);
			menu.add(0,3,3,R.string.help);
			return super.onCreateOptionsMenu(menu);
		}
		@Override
		public boolean onOptionsItemSelected(MenuItem item) {
			// TODO Auto-generated method stub
			if(item.getItemId()==1){
				AlertDialog dialog = new AlertDialog.Builder(Msg.this)  
	            .setIcon(android.R.drawable.btn_star_big_on)  
	            .setTitle(R.string.tuichu)  
	          .setPositiveButton(R.string.determine, onclick)  
	            .setNegativeButton(R.string.cancel,  onclick).create();  
					dialog.show();
			}else if(item.getItemId()==2){
				item.setIntent(new Intent(this, Options.class));
			}else if(item.getItemId()==3){
				item.setIntent(new Intent(this, Help.class));
			}
			return super.onOptionsItemSelected(item);
		}
		OnClickListener onclick = new OnClickListener() { 
	        public void onClick(DialogInterface dialog, int which) {  
	            switch (which) {  
	                case Dialog.BUTTON_NEGATIVE:  
	                    break;  
	                case Dialog.BUTTON_POSITIVE:
	                	Intent startMain = new Intent(Intent.ACTION_MAIN);
	        			startMain.addCategory(Intent.CATEGORY_HOME);
	        			startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	        			startActivity(startMain);
	        			System.exit(0);
	                    break;  
	            } 
	        }
	    };
}
